package com.uhylab.uhuvinetest.view.painter.digital;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;


/**
 * @author Adrián García Lomas
 *         修改文字居中
 */
public class DigitalImp implements Digital {

    private float value;
    protected Paint digitPaint2;//分别小时小数点前和后的
    private float textSize;
    private int color;
    private float centerX;
    private float centerY;

    public DigitalImp(int color, Context context, int marginTop, int textSize, String units) {
        this.color = color;
        this.textSize = textSize;
        initTypeFace();
        initPainter();
        initValues();
    }

    private void initPainter() {
        digitPaint2 = new Paint();
        digitPaint2.setAntiAlias(true);
        digitPaint2.setTextSize(textSize * 2);
        digitPaint2.setColor(color);
        digitPaint2.setTextAlign(Paint.Align.CENTER);

    }

    private void initValues() {
    }

    private void initTypeFace() {
    }

    @Override
    public void setValue(float value) {
        this.value = value;
    }

    @Override
    public void draw(Canvas canvas) {
        Paint.FontMetrics fontMetrics = digitPaint2.getFontMetrics();
        float fontHeight = fontMetrics.bottom - fontMetrics.top;
        float baseLineY = centerY * 2 - (centerY * 2 - fontHeight) / 2 - fontMetrics.bottom;
        canvas.drawText("" + (int) (45 - value), centerX, baseLineY,
                digitPaint2);
    }

    @Override
    public void setColor(int color) {
        this.color = color;
    }

    @Override
    public int getColor() {
        return this.color;
    }

    @Override
    public void onSizeChanged(int height, int width) {
        this.centerX = width / 2;
        this.centerY = height / 2;
    }
}
